package com.kstudio.ksnapshot;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;

public final class KUtil {

    private boolean LOG;
    private String TAG;

    private static final boolean KListActivity = true;
    private static final boolean KListAdapter = false;

    private static final boolean KImageActivity = true;

    private static final boolean KEditActivity = false;
    private static final boolean KEditControl = false;
    private static final boolean KEditVideoPlayer = false;

    private static final boolean KSnapShotAsync = true;
    private static final boolean KAnimation = false;

    private static final boolean KSeekView = false;
    private static final boolean KSubIconView = false;

    public KUtil(String tag) {
        TAG = tag;

        if(tag.equals("KListActivity")) {
            LOG = KListActivity;
        } else if(tag.equals("KListAdapter")) {
            LOG = KListAdapter;
        } else if(tag.equals("KImageActivity")) {
            LOG = KImageActivity;
        } else if(tag.equals("KEditActivity")) {
            LOG = KEditActivity;
        } else if(tag.equals("KEditControl")) {
            LOG = KEditControl;
        } else if(tag.equals("KEditVideoPlayer")) {
            LOG = KEditVideoPlayer;
        } else if(tag.equals("KSnapShotAsync")) {
            LOG = KSnapShotAsync;
        } else if(tag.equals("KAnimation")) {
            LOG = KAnimation;
        } else if(tag.equals("KSeekView")) {
            LOG = KSeekView;
        } else if(tag.equals("KSubIconView")) {
            LOG = KSubIconView;
        } else {
            LOG = false;
            e("%s tag is not define",TAG);
        }
    }

    public void v(String format, Object... args) {
        if(LOG) Log.v(TAG, String.format(format, args));
    }

    public void d(String format, Object... args) {
        if(LOG) Log.d(TAG, String.format(format, args));
    }

    public void i(String format, Object... args) {
        if(LOG) Log.i(TAG, String.format(format, args));
    }

    public void w(String format, Object... args) {
        if(LOG) Log.v(TAG, String.format(format, args));
    }

    public void e(String format, Object... args) {
        Log.e(TAG, String.format(format, args));
    }

    public static Bitmap ModifyBitmap(Bitmap bitmap, int width, int height) {
        int modifyWidth = width;
        int modifyHeight = height;
        Bitmap b = null;

        if(bitmap != null) {
            if(bitmap.getWidth() >= bitmap.getHeight()) {
                modifyHeight = modifyHeight * bitmap.getHeight() / bitmap.getWidth();
            } else {
                modifyWidth = modifyWidth * bitmap.getWidth() / bitmap.getHeight();
            }
            b = Bitmap.createScaledBitmap(bitmap, modifyWidth, modifyHeight, false);
        }

        return b;
    }

    public static Bitmap ModifyBitmap(String path, int width, int height) {
        Bitmap bitmap = BitmapFactory.decodeFile(path);
        Bitmap b = null;

        if(bitmap != null) {
            b = ModifyBitmap(bitmap, width, height);
            bitmap.recycle();
        }
        return b;
    }
}